<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>响应式小精灵 - Vue 示例</title>
  <!-- 引入 Vue 3 -->
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <style>
    body {
      font-family: Arial, sans-serif;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
      background-color: #f0f0f0;
    }
    .game-container {
      text-align: center;
      padding: 2rem;
      background-color: white;
      border-radius: 8px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }
    button {
      padding: 10px 20px;
      font-size: 16px;
      cursor: pointer;
      background-color: #4CAF50;
      color: white;
      border: none;
      border-radius: 4px;
      transition: background-color 0.3s;
    }
    button:hover:not(:disabled) {
      background-color: #45a049;
    }
    button:disabled {
      background-color: #cccccc;
      cursor: not-allowed;
    }
  </style>
</head>
<body>
  <div id="app" class="game-container">
    <h1>响应式小精灵</h1>
    <script setup>
      // 使用Vue全局对象中的ref
      const hp = Vue.ref(100)          // 英雄血量
      const attacking = Vue.ref(false) // 是否正在攻击

      // 修改数据
      const attack = () => {
        attacking.value = true
        setTimeout(() => {
          hp.value -= 20
          attacking.value = false
        }, 500)
      }
    </script>

    <template>
      <h2>勇者血量：{{ hp }}</h2>
      <button @click="attack" :disabled="attacking">
        {{ attacking ? '攻击中...' : '发起攻击' }}
      </button>
    </template>
  </div>

  <script>
    const app = Vue.createApp({
      template: '#app > template'
    })
    app.mount('#app')
  </script>
</body>
</html>